#!/bin/bash -e

if [ $# == 0 ] ; then
   echo "please input version"
   exit 0
fi

sudo rm -rf /docker/config/hproxy

sudo rm -rf /docker/logs/hproxy

sudo mkdir -p /docker/config/hproxy

echo "---created /docker/v2ray/"

sudo mkdir -p /docker/logs/hproxy

echo "---created /docker/v2ray/logs"

echo "---start pull v2ray/official----"
docker login registry.cn-shanghai.aliyuncs.com
docker pull registry.cn-shanghai.aliyuncs.com/v_swarm/v-proxy:$1-SNAPSHOT
echo "---end ------"

wget -P /docker/config/hproxy  https://gitee.com/ostls/shell_v2/raw/master/hebao/config_proxy.properties

mv /docker/config/hproxy/config_proxy.properties /docker/config/hproxy/application-prod.properties


if [ ! -d "/docker/config/proxy/application-prod.properties" ];then
   	#sudo chmod -R 776 /docker/v2ray/config.json
	echo "found application-prod.properties"
   else
	exit 0
fi

echo "---start run docker----"
set +e
docker stop h-proxy
docker rm h-proxy
set -e
docker run --net host -d -p $2:$2 -p $3:$3 --restart=always --log-driver="none" -v /docker/config/hproxy:/config -v /docker/logs/hproxy:/logs --name=h-proxy -e "spring.profiles.active=prod" registry.cn-shanghai.aliyuncs.com/v_swarm/v-proxy:$1-SNAPSHOT
echo "---start sccuess-------"
